<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>用户信息添加</title>
    <link href="<%=basePath%>css/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $('tbody tr:odd').addClass("trLight");
            $(".select-all").click(function(){
                if($(this).attr("checked")){
                    $(".checkBox input[type=checkbox]").each(function(){
                        $(this).attr("checked", true);
                    });
                }else{
                    $(".checkBox input[type=checkbox]").each(function(){
                        $(this).attr("checked", false);
                    });
                }
            });
        });
        function checkUser(){
            $("#msg").text("");
            var username = $("#username").val();
            $.ajax({
                url:"<%=basePath%>checkUser?username="+username,
                dataType : "json",
                //编码设置
                contentType : "application/json;charset=utf-8",
                success : function(data) {
                    if (data.msg != null) {
                        //alert(data.msg);onblur事件不建议使用弹窗
                        $("#msg").append(data.msg);
                        $("#username").val("");
                        $("#username").focus();
                    }
                },
                error:function(){
                    alert("后台服务器出错，请联系系统管理员！");
                }
            })
        }
        function goback(){
            window.location.href = "<%=basePath%>userListController";
        }
    </script>
    <style type="text/css">
        body {
            background:#FFF
        }
        #message{
            font-style: italic;
            font-size: larger;
            color:red;
        }
        #msg{
            /*font-size: large;*/
            color:red;
        }
    </style>
</head>
<body>
<form method="post" action="<%=basePath%>userAddController" method="post" name="ThisForm">
    <div id="contentWrap">
        <!--表格控件 -->
        <div id="widget table-widget">
            <div class="pageTitle">用户添加</div>
            <div class="pageInfo">
                <label id="message">${success}</label>
                <table >
                    <tr>
                        <td width="20%" align="right">用户名</td>
                        <td width="20%"><input type="text" id="username" name="username" value="${user.username}" onblur="checkUser()"/>
                            <lable id="msg"></lable></td>
                        <td width="10%" align="right">用户密码</td>
                        <td width="50%"><input type="password" id="password" name="password" value="${user.password}"/></td>
                    </tr>
                    <tr>
                        <td width="20%" align="right">姓名</td>
                        <td width="20%"><input type="text" id="realname" name="realname" value="${user.realname}"/></td>
                        <td width="10%" align="right">用户类型</td>
                        <td width="50%">
                            <select id="type" name="role" >
                                <option value="">-请选择-</option>
                                <c:if test="${user.role=='01'}"> <option value="01" selected>管理人员</option></c:if>
                                <c:if test="${user.role!='01'}"><option value="01">管理人员</option></c:if>
                                <c:if test="${user.role!='02'}"><option value="02">服务台员工</option></c:if>
                                <c:if test="${user.role=='02'}"><option value="02" selected>服务台员工</option></c:if>
                                <c:if test="${user.role=='03'}"> <option value="03" selected>药剂师</option></c:if>
                                <c:if test="${user.role!='03'}"> <option value="03">药剂师</option></c:if>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td width="10%" align="right">联系电话</td>
                        <td width="50%"><input type="text" id="tel" name="tel" value="${user.tel}"/></td>
                        <td width="20%" align="right">年龄</td>
                        <td width="20%"><input type="text" id="age" name="age" value="${user.age}"/></td>
                    </tr>
                    <tr>
                        <td width="20%" align="right">性别</td>
                        <td width="20%">
                            <select id="depart" name="sex" >
                                <option value="">请选择</option>
                                <c:if test="${user.sex=='1'}"> <option value="1" selected>男</option></c:if>
                                <c:if test="${user.sex!='1'}"> <option value="1" >男</option></c:if>
                                <c:if test="${user.sex=='0'}"> <option value="0" selected>女</option></c:if>
                                <c:if test="${user.sex!='0'}"> <option value="0" >女</option></c:if>
                            </select>
                        </td>
                        <td width="10%" align="right">家庭住址</td>
                        <td width="50%"><input type="text" id="address" name="address"  value="${user.address}"/></td>

                    </tr>
                    <tr>
                        <td colspan="4" align="center">
                            <c:if test="${flag!='1'}">
                                <input type="submit" value="确定"/>
                            </c:if>
                            <input type="button"	value="返回" onclick="goback()"/>
                        </td>
                    </tr>
                </table>
            </div>
        </div><!-- #widget -->
    </div>
</form>
</body>
</html>